﻿Public Class frmNetAddGroup
    Public Result As MsgBoxResult

    Private Sub SanitizeInput()
        txtDisplayName.Text = txtDisplayName.Text.Trim
    End Sub

    Private Function ValidateInput() As Boolean
        If frmBrowser.NameExists(txtDisplayName.Text) Then
            InvMsg("Display Name already exists within your network tree.")
            txtDisplayName.Focus()
            Return False
        End If
        If txtDisplayName.Text = "" Then
            InvMsg("Display Name cannot be empty.")
            txtDisplayName.Focus()
            Return False
        End If
        Return True
    End Function

    Private Sub InvMsg(Message As String)
        MsgBox(Message, MsgBoxStyle.Exclamation Or MsgBoxStyle.OkOnly, "PurpleKnife")
    End Sub

    Private Sub btnOK_Click(sender As System.Object, e As System.EventArgs) Handles btnOK.Click
        Call SanitizeInput()
        If ValidateInput() Then
            Result = MsgBoxResult.Ok
            Me.Hide()
        End If
    End Sub
    Private Sub btnCancel_Click(sender As System.Object, e As System.EventArgs) Handles btnCancel.Click
        Result = MsgBoxResult.Cancel
        Me.Hide()
    End Sub

    Private Sub frmNetAddSwitch_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated
        txtDisplayName.Focus()
    End Sub
End Class